import type { IQuery, IResponse, TableResponse } from '@/api/config/types';
import axios from 'axios';

export interface Field {
  fieldId: string;
  fieldName: string;
  status: string;
  isDel: string;
  fieldType: '0' | '1' | '2';
  modal?: boolean;
}

const prefix = '/goods/field';

// 查询商品字段列表
export const listField = (query?: IQuery) => {
  return axios.get<TableResponse<Field>>(`${prefix}/list`, { params: query });
};

// 查询商品字段
export const queryField = (query?: { fieldType: 1 | 0 | 2; status?: 0 | 1 }) => {
  return axios.get<TableResponse<Field>>(`${prefix}/query`, { params: query });
};

// 删除商品字段
export const delField = (fieldId: (string | number)[]) => {
  return axios.delete<IResponse<any>>(`${prefix}/${fieldId.join(',')}`);
};

// 获取商品字段
export const getField = (fieldId: string) => {
  return axios.get<IResponse<Field>>(`${prefix}/${fieldId}`);
};

// 新增商品字段
export const addField = (data: Field) => {
  return axios.post<IResponse<string>>(`${prefix}`, data);
};

// 修改商品字段
export const updateField = (data: Field) => {
  return axios.put<IResponse>(`${prefix}`, data);
};
